package com.gs.spring.core;

import java.util.Random;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class GreetingBean {
	
	String message;
	
	
	String greetedBy;
	
	//this annotation is disallowed for this location
//	@Required
	SimpleBean simpleBean;
	
	@Value("#{systemProperties['user.name']}")
	String userName;

	@Value("#{systemProperties['os.name']}")
	String userRegion;
	
//	@Value("#{numberGuess.randomNumber}")
	int randomNumber;
	
	@PostConstruct
	public void init(){
		System.out.println("Init method called on annotated method.");
		message = "Message has been initialized.";
	}


	public String getMessage() {
		return message;
	}


	public void setMessage(String message) {
		this.message = message;
	}


	public String getGreetedBy() {
		String msg = (greetedBy==null?userName:greetedBy) + " from " + userRegion ; 
		msg += " at random ";
		msg += randomNumber;
		return msg;
	}

	public void setGreetedBy(String greetedBy) {
		this.greetedBy = greetedBy;
	}


	public SimpleBean getSimpleBean() {
		return simpleBean;
	}

	@Required
	@Autowired	
	public void setSimpleBean(SimpleBean simpleBean) {
		this.simpleBean = simpleBean;
	}
	
}
